<!DOCTYPE html>
<html>
<html lang="en">
<head>
    <meta charset="utf-8">

</head>
<link rel="stylesheet" href="/richText/bootstrap-combined.no-icons.min.css" type="text/css">
<link rel="stylesheet" href="/richText/index.css" type="text/css"></link>
<link href="http://netdna.bootstrapcdn.com/font-awesome/3.0.2/css/font-awesome.css" rel="stylesheet">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap-responsive.min.css">
<link rel="stylesheet" href="css/font-awesome.min.css">
<link rel="stylesheet" href="css/ace.min.css">
<link rel="stylesheet" href="css/ace-skins.min.css">
<link rel="stylesheet" href="css/ace-responsive.min.css">

<script src="js/jquery-1.9.1.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootbox.min.js"></script>
<style>
    body, html {
        width: 100%;
        height: 100%;
        background: #fff;
    }

    .info div {
        float: right;
    }

    #editor {
        height: 200px;
    }

    #main-content {
        margin-left: 190px;
    }

    #page-content {
        margin: 0;
        background: #FFF;
        position: relative;
        top:0%;
        left:-10%;
    }
    .modal-footer {
        background: #fff;
    }
</style>
<body>

<div id="main-content" class="clearfix">
    <div id="page-content" class="clearfix">

        <div class="page-header position-relative">
            <h1 style="color: #2679b5;">品牌商
                <small><i class="icon-double-angle-right"></i> 订单管理</small>
            </h1>
        </div>
        <!--<form class="form-search">-->
        <!--商品标题：-->
        <!--<input type="text" class="input-medium search-query">-->
        <!--<button onclick="return false;" class="btn btn-purple btn-small">Search <i class="icon-search icon-on-right"></i></button>-->
        <!--</form>-->

        <div class="tabbable">
            <ul class="nav nav-tabs" id="myTab">
                <li class="active"><a data-toggle="tab" href="#AwaitingPayment"> 待支付</a></li>
                <li class=""><a data-toggle="tab" href="#AwaitingShipment"> 待发货</a></li>
                <li class=""><a data-toggle="tab" href="#shipped">已发货</a></li>
                <li class=""><a data-toggle="tab" href="#complete">已完成</a></li>
                <li class=""><a data-toggle="tab" href="#canceled">已取消</a></li>
            </ul>
            <div class="tab-content">
                <div id="AwaitingPayment" class="tab-pane active">
                    <p>
                    <table id="table_bug_report1" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th class="center">
                                <label><input type="checkbox" class="ace-checkbox-2"><span class="lbl"></span></label>
                            </th>
                            <th>商品标题</th>
                            <th>订单总额</th>
                            <th class="hidden-480">数量</th>
                            <th>sku</th>
                            <th class="hidden-480">订单编号</th>
                            <th class="hidden-480">订单创建时间</th>
                        </tr>
                        </thead>

                        <tbody id="tobepaid"></tbody>
                    </table>
                    </p>
                </div>
                <div id="AwaitingShipment" class="tab-pane">
                    <p>
                    <table id="table_bug_report2" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th class="center">
                                <label><input type="checkbox" class="ace-checkbox-2"><span class="lbl"></span></label>
                            </th>
                            <th>商品标题</th>
                            <th>价格</th>
                            <th class="hidden-480">数量</th>
                            <th>sku</th>
                            <th class="hidden-480">订单编号</th>
                            <th class="hidden-480">订单创建时间</th>

                            <th>操作</th>
                        </tr>
                        </thead>

                        <tbody id="toBeShipped">


                        </tbody>
                    </table>
                    </p>
                </div>
                <div id="shipped" class="tab-pane">
                    <p>
                    <table id="table_bug_report3" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th class="center">
                                <label><input type="checkbox" class="ace-checkbox-2"><span class="lbl"></span></label>
                            </th>
                            <th>商品标题</th>
                            <th>价格</th>
                            <th class="hidden-480">数量</th>
                            <th>sku</th>
                            <th>订单编号</th>
                            <th class="hidden-480">订单创建时间</th>
                            <th class="hidden-480">物流跟踪号</th>
                            <th>操作</th>
                        </tr>
                        </thead>

                        <tbody id="sended">


                        </tbody>
                    </table>
                    </p>
                </div>
                <div id="complete" class="tab-pane">
                    <p>
                    <table id="table_bug_report4" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th class="center">
                                <label><input type="checkbox" class="ace-checkbox-2"><span class="lbl"></span></label>
                            </th>
                            <th>商品标题</th>
                            <th>价格</th>
                            <th class="hidden-480">数量</th>
                            <th>sku</th>
                            <th>订单编号</th>
                            <th class="hidden-480">订单创建时间</th>
                            <th class="hidden-480">物流跟踪号</th>

                        </tr>
                        </thead>

                        <tbody id="finished">


                        </tbody>
                    </table>
                    </p>
                </div>
                <div id="canceled" class="tab-pane">
                    <p>
                    <table id="table_bug_report" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th class="center">
                                <label><input type="checkbox" class="ace-checkbox-2"><span class="lbl"></span></label>
                            </th>
                            <th>商品标题</th>
                            <th>价格</th>
                            <th class="hidden-480">数量</th>
                            <th>sku</th>
                            <th>订单编号</th>
                            <th class="hidden-480">订单创建时间</th>

                        </tr>
                        </thead>

                        <tbody id="vanished">
                        </tbody>
                    </table>
                    </p>
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    var mvo_id


    $(function () {
        var url = location.search;
        var Request = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1)　//去掉?号
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                Request[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
            }
        }

        mvo_id = Request["uid"]
        console.log(mvo_id);
        //将需要修改信息的商品ID传到该页面
        // $("#index").attr('href','/role?uid='+mvo_id);
    })

    //获取待支付订单列表
    $(function () {

        var $tbody = $('#tobepaid')

        $.ajax({
            type: 'post',
            url: '/order/selectToBePaidFromOrder',
            data: {mvoId: mvo_id},
            dataType: 'json',
            async: false,
            success: function (list) {
                // alert('good')
                console.log(list)
                // alert(list.length)
                var newHtml = '';
                //循环每一条订单
                for (var k = 0; k < list.length; k++) {
                    var title
                    var sku
                    var num
                    // for(var n in list){
                    //     console.log(n)
                    // }
                    //通过该订单ID获取商品列表(商品标题 ,sku)
                    $.ajax({
                        type: 'post',
                        url: '/ordergoods/selectGoodByOrderID',
                        data: {id: list[k].id},
                        dataType: 'json',
                        async: false,
                        success: function (good) {
                            // console.log(good)'
                            // alert('通过该订单ID获取商品列表(商品标题 ,sku)')
                            for (var i = 0; i < good.length; i++) {
                                //获取当前订单的商品数量
                                $.ajax({
                                    type:'post',
                                    url: '/ordergoods/selectOrderGoodsByGoodsIDAndOrderID',
                                    data: {goodsID: good[i].id, orderID: list[k].id},
                                    dataType: 'json',
                                    async: false,
                                    success: function (obj) {
                                        // alert('fuckoffffffffffffff')
                                        num = obj.goodsNum
                                    },
                                    error: function () {
                                        alert("error404")
                                    }
                                })

                                title = good[i].title
                                sku = good[i].sku
                                newHtml += '<tr>';
                                newHtml += '          <td class="center">';
                                newHtml += '            <label><input type="checkbox" class="input"><span class="lbl"></span></label>';
                                newHtml += '          </td>';
                                newHtml += '          <td><a href="#" onclick="gotogoodsdetail(' + i + ',' + num + ',' + good[i].brandId + ',' + ')">' + title + '</a></td>';
                                newHtml += '          <td>￥' + list[k].totalMoney + '</td>';
                                newHtml += '          <td class="hidden-480">' + num + '</td>';
                                newHtml += '          <td class="">' + sku + '</td>';
                                newHtml += '          <td class="hidden-480">' + list[k].id + '</td>';
                                newHtml += '          <td class="">' + list[k].createTime + '</td>';
                                newHtml += '          <tr>';
                            }
                            $tbody.html(newHtml)
                        },//每个商品
                        error: function () {
                            alert("第一层")
                        }
                    })
                }
            },
            error: function () {
                //alert("nogood")
            }

        })


    })

    //待发货列表
    $(function () {
        var $tbody = $('#toBeShipped')
        //获取待支付订单列表
        $.ajax({
            type: 'post',
            url: '/order/selectToBeDeliveredFromOrder',
            data: {mvoId: mvo_id},
            dataType: 'json',
            async: false,
            success: function (list) {
                // alert('good')
                console.log(list)
                // alert(list.length)
                var newHtml = '';
                //循环每一条订单
                for (var k = 0; k < list.length; k++) {
                    var title
                    var sku
                    var num
                    // for(var n in list){
                    //     console.log(n)
                    // }
                    //通过该订单ID获取商品列表(商品标题 ,sku)
                    $.ajax({
                        type: 'post',
                        url: '/ordergoods/selectGoodByOrderID',
                        data: {id: list[k].id},
                        dataType: 'json',
                        async: false,
                        success: function (good) {
                            // console.log(good)
                            for (var i = 0; i < good.length; i++) {

                                //获取当前订单的商品数量
                                $.ajax({
                                    type: 'post',
                                    url: '/ordergoods/selectOrderGoodsByGoodsIDAndOrderID',
                                    data: {goodsID: good[i].id, orderID: list[k].id},
                                    dataType: 'json',
                                    async: false,
                                    success: function (obj) {
                                        num = obj.goodsNum
                                    },
                                    error: function () {
                                        alert("error404")
                                    }
                                })

                                title = good[i].title
                                sku = good[i].sku
                                newHtml += '<tr>';
                                newHtml += '          <td class="center">';
                                newHtml += '            <label><input type="checkbox" class="input"><span class="lbl"></span></label>';
                                newHtml += '          </td>';
                                newHtml += '          <td><a th:href="@{/goodsDetail}">' + title + '</a></td>';
                                newHtml += '          <td>￥' + list[k].totalMoney + '</td>';
                                newHtml += '          <td class="hidden-480">' + num + '</td>';
                                newHtml += '          <td class="">' + sku + '</td>';
                                newHtml += '          <td class="hidden-480">' + list[k].id + '</td>';
                                newHtml += '          <td class="">' + list[k].createTime + '</td>';
                                newHtml += '          <td class=""><button  onclick="ship(' + list[k].id + ')">发货</button></td>';
                                newHtml += '          <tr>';
                            }
                            $tbody.html(newHtml)

                        },//每个商品
                        error: function () {
                            alert("第一层")
                        }
                    })
                }
            },
            error: function () {
                //alert("nogood")
            }

        })
    })

    //已发货
    $(function () {
        var $tbody = $('#sended')
        //获取待支付订单列表
        $.ajax({
            type: 'post',
            url: '/order/selectDeliveredFromOrder',
            data: {mvoId: mvo_id},
            dataType: 'json',
            async: false,
            success: function (list) {
                // alert('good')
                console.log(list)
                // alert(list.length)
                var newHtml = '';
                //循环每一条订单
                for (var k = 0; k < list.length; k++) {
                    var title
                    var sku
                    var num
                    // for(var n in list){
                    //     console.log(n)
                    // }
                    //通过该订单ID获取商品列表(商品标题 ,sku)
                    $.ajax({
                        type: 'post',
                        url: '/ordergoods/selectGoodByOrderID',
                        data: {id: list[k].id},
                        dataType: 'json',
                        async: false,
                        success: function (good) {
                            // console.log(good)
                            for (var i = 0; i < good.length; i++) {

                                //获取当前订单的商品数量
                                $.ajax({
                                    type: 'post',
                                    url: '/ordergoods/selectOrderGoodsByGoodsIDAndOrderID',
                                    data: {goodsID: good[i].id, orderID: list[k].id},
                                    dataType: 'json',
                                    async: false,
                                    success: function (obj) {
                                        num = obj.goodsNum
                                    },
                                    error: function () {
                                        alert("error404")
                                    }
                                })

                                title = good[i].title
                                sku = good[i].sku
                                newHtml += '<tr>';
                                newHtml += '          <td class="center">';
                                newHtml += '            <label><input type="checkbox" class="input"><span class="lbl"></span></label>';
                                newHtml += '          </td>';
                                newHtml += '          <td><a th:href="@{/goodsDetail}">' + title + '</a></td>';
                                newHtml += '          <td>￥' + list[k].totalMoney + '</td>';
                                newHtml += '          <td class="hidden-480">' + num + '</td>';
                                newHtml += '          <td class="">' + sku + '</td>';
                                newHtml += '          <td class="hidden-480">' + list[k].id + '</td>';
                                newHtml += '          <td class="">' + list[k].createTime + '</td>';
                                newHtml += '          <td class="">' + list[k].sendNo + '</td>';
                                newHtml += '          <td class=""><button onclick="qui(' + list[k].id + ')">取消</button></td>';
                                newHtml += '          <tr>';

                            }
                            $tbody.html(newHtml)

                        },//每个商品
                        error: function () {
                            alert("第一层")
                        }
                    })
                }
            },
            error: function () {
                //alert("nogood")
            }

        })
    })

    //已完成
    $(function () {
        var $tbody = $('#finished')
        //获取待支付订单列表
        $.ajax({
            type: 'post',
            url: '/order/selectFinishedFromOrder',
            data: {mvoId: mvo_id},
            dataType: 'json',
            async: false,
            success: function (list) {
                // alert('good')
                console.log(list)
                // alert(list.length)
                var newHtml = '';
                //循环每一条订单
                for (var k = 0; k < list.length; k++) {
                    var title
                    var sku
                    var num
                    // for(var n in list){
                    //     console.log(n)
                    // }
                    //通过该订单ID获取商品列表(商品标题 ,sku)
                    $.ajax({
                        type: 'post',
                        url: '/ordergoods/selectGoodByOrderID',
                        data: {id: list[k].id},
                        dataType: 'json',
                        async: false,
                        success: function (good) {
                            // console.log(good)
                            for (var i = 0; i < good.length; i++) {

                                //获取当前订单的商品数量
                                $.ajax({
                                    url: '/ordergoods/selectOrderGoodsByGoodsIDAndOrderID',
                                    data: {goodsID: good[i].id, orderID: list[k].id},
                                    dataType: 'json',
                                    async: false,
                                    success: function (obj) {
                                        num = obj.goodsNum
                                    },
                                    error: function () {
                                        alert("error404")
                                    }
                                })

                                title = good[i].title
                                sku = good[i].sku
                                newHtml += '<tr>';
                                newHtml += '          <td class="center">';
                                newHtml += '            <label><input type="checkbox" class="input"><span class="lbl"></span></label>';
                                newHtml += '          </td>';
                                newHtml += '          <td><a th:href="@{/goodsDetail}">' + title + '</a></td>';
                                newHtml += '          <td>￥' + list[k].totalMoney + '</td>';
                                newHtml += '          <td class="hidden-480">' + num + '</td>';
                                newHtml += '          <td class="">' + sku + '</td>';
                                newHtml += '          <td class="hidden-480">' + list[k].id + '</td>';
                                newHtml += '          <td class="">' + list[k].createTime + '</td>';
                                newHtml += '          <td class="">' + list[k].sendNo + '</td>';
                                newHtml += '          <tr>';


                            }
                            $tbody.html(newHtml)

                        },//每个商品
                        error: function () {
                            alert("第一层")
                        }
                    })
                    // newHtml+='<tr>';
                    // newHtml+='          <td class="center">';
                    // newHtml+='            <label><input type="checkbox" class="input"><span class="lbl"></span></label>';
                    // newHtml+='          </td>';
                    // newHtml+='          <td><a th:href="@{/goodsDetail}">'+ title +'</a></td>';
                    // newHtml+='          <td>￥' + list[k].totalMoney+ '</td>';
                    // newHtml+='          <td class="hidden-480">'+num+'</td>';
                    // newHtml+='          <td class="">'+ sku + '</td>';
                    // newHtml+='          <td class="hidden-480">'+ list[k].sendNo+'</td>';
                    // newHtml+='          <td class="">' +list[k].createTime+ '</td>';
                    // newHtml+='          <tr>';

                }
                // $tbody.html(newHtml)


            },
            error: function () {
                //alert("nogood")
            }

        })
    })


    //已取消
    $(function () {
        var $tbody = $('#vanished')
        //获取待支付订单列表
        $.ajax({
            type: 'post',
            url: '/order/selectCanceledFromOrder',
            data: {mvoId: mvo_id},
            dataType: 'json',
            async: false,
            success: function (list) {
                // alert('good')
                console.log(list)
                // alert(list.length)
                var newHtml = '';
                //循环每一条订单
                for (var k = 0; k < list.length; k++) {
                    var title
                    var sku
                    var num
                    // for(var n in list){
                    //     console.log(n)
                    // }
                    //通过该订单ID获取商品列表(商品标题 ,sku)
                    $.ajax({
                        type: 'post',
                        url: '/ordergoods/selectGoodByOrderID',
                        data: {id: list[k].id},
                        dataType: 'json',
                        async: false,
                        success: function (good) {
                            // console.log(good)
                            for (var i = 0; i < good.length; i++) {

                                //获取当前订单的商品数量
                                $.ajax({
                                    url: '/ordergoods/selectOrderGoodsByGoodsIDAndOrderID',
                                    data: {goodsID: good[i].id, orderID: list[k].id},
                                    dataType: 'json',
                                    async: false,
                                    success: function (obj) {
                                        num = obj.goodsNum
                                    },
                                    error: function () {
                                        alert("error404")
                                    }
                                })

                                title = good[i].title
                                sku = good[i].sku
                                newHtml += '<tr>';
                                newHtml += '          <td class="center">';
                                newHtml += '            <label><input type="checkbox" class="input"><span class="lbl"></span></label>';
                                newHtml += '          </td>';
                                newHtml += '          <td><a href="#">' + title + '</a></td>';
                                newHtml += '          <td>￥' + list[k].totalMoney + '</td>';
                                newHtml += '          <td class="hidden-480">' + num + '</td>';
                                newHtml += '          <td class="">' + sku + '</td>';
                                newHtml += '          <td class="hidden-480">' + list[k].sendNo + '</td>';
                                newHtml += '          <td class="">' + list[k].createTime + '</td>';
                                newHtml += '          <tr>';
                            }
                            $tbody.html(newHtml)
                        },//每个商品
                        error: function () {
                            alert("第一层")
                        }
                    })
                }
            },
            error: function () {
                //alert("nogood")
            }
        })
    })

    //发货按钮操作
    function ship(id) {
        // alert("test")
        if (confirm("确认发货？")) {
            $.ajax({
                type: 'post',
                url: '/order/updateOrderState',
                data: {id: id, state: 'C'},
                dataType: 'text',
                async: false,
                success: function (re) {
                    console.log(re)
                    alert(re)
                    window.location.reload()
                },
                error: function () {
                    alert("发货异常")
                }
            })
        }

    }

    //取消发货按钮操作
    function qui(id) {
        // alert("test")
        if (confirm("确认取消发货？")) {
            $.ajax({
                type: 'post',
                url: '/order/updateOrderState',
                data: {id: id, state: 'E'},
                dataType: 'text',
                async: false,
                success: function (re) {
                    console.log(re)
                    alert(re)
                    window.location.reload()
                },
                error: function () {
                    alert("取消发货异常")
                }
            })
        }

    }


    $(function () {

        $('.ace-checkbox-2').each(function () {
            $('.ace-checkbox-2').change(function () {
                if ($(this).prop('checked')) {
                    $(this).parents('.tab-pane').find('.input').prop('checked', true);
                } else {
                    $(this).parents('.tab-pane').find('.input').prop('checked', false);
                }
            })

        })

        $('.send-out').click(function () {
            bootbox.alert("已发货!");
        })
        $('.cancel').click(function () {
            bootbox.alert("订单已取消!");
        })
    })

</script>
</body>
</html>
